﻿#include "ObjectFactory.h"

std::shared_ptr<ObjectFactory> objFactoryPtr { nullptr };

int ObjectFactory::RegisterObj(const QString& className, ObjCreator objCreator)
{
    creatorMap[className] = objCreator;
    return 0;   //这个返回值并非无意义，通过将返回值赋予一个不使用的static类变量，可以保证在程序运行初期，RegisterObj被调用。
}

std::shared_ptr<Object> ObjectFactory::CreateObj(const QString& className)
{
    auto creator = creatorMap[className];
    if (creator == nullptr)
        return nullptr;
    else
        return creator();
}
